<?php

namespace App\Http\Controllers;

use Illuminate\Contracts\Pagination\LengthAwarePaginator;

class LayuiController
{
    static public function apiResponse( $data = [], $code = 200, $msg = ''){
        return response()->json([
            'code'      => $code,
            'message'   => $msg,
            'data'      => $data,
        ]);
    }

    static public function tableJson($data = [], $code = 0 , $count = 0, $msg = '' ){
        if(!is_array($data) && $data instanceof LengthAwarePaginator){
            $count = $data->total();
            $data = $data->items();
        }

        $data = [
            'code'  => $code,
            'msg'   => $msg,
            'count' => $count,
            'data'  => $data,
        ];

        return $data;
    }

}
